import os

# 列表生成式

a_list = [x * x for x in range(1, 10)]
print(a_list)

b_list = [x * x for x in range(10) if x % 2 == 0]
print(b_list)

# 双层循环
c_list = [x + y for x in "ABC" for y in "XYZ"]
print(c_list)

# 列出当前目录下的所有文件和目录名
print([d for d in os.listdir('./')])
# 上级
print([d for d in os.listdir('../')])

a_dict = {'a': 1, 'b': 2, 'c': 3}
# 必须是str
print([x + '=' + str(y) for x, y in a_dict.items()])

d_list = ['Hello', 'world']
# 转小写
print([s.lower() for s in d_list])

e_list = ['Hello', 22, 'world']
print([s.lower() for s in e_list if isinstance(s, str)])
